#!/usr/bin/env bash
printf '%s\n' '检测到您使用的是WSL,正在为您打开音频服务'
export PULSE_SERVER=tcp:127.0.0.1
cd "/mnt/c/Users/Public/Downloads/pulseaudio"
/mnt/c/WINDOWS/system32/cmd.exe /c "start .\pulseaudio.bat"
printf "%s\n" "若无法自动打开音频服务，则请手动在资源管理器中打开C:\Users\Public\Downloads\pulseaudio\pulseaudio.bat"
if grep -q '172..*1' "/etc/resolv.conf"; then
    printf "%s\n" "检测到您当前使用的可能是WSL2"
    WSL2IP=$(sed -n p /etc/resolv.conf | grep nameserver | awk '{print $2}' | head -n 1)
    #sed -i "s/^export PULSE_SERVER=.*/export PULSE_SERVER=${WSL2IP}/g" ~/.vnc/xstartup
    export PULSE_SERVER=${WSL2IP}
    printf "%s\n" "已将您的音频服务ip修改为${WSL2IP}"
fi
sleep 2
